package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.Question;
import com.itheima.domain.db.SoulQuestion;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.manager.QuestionManger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class QuestionController {

    @Autowired
    private QuestionManger questionManger;

    /*
     *  分页查询灵魂问题表
     *
     * @param num   当前页
     * @param size  每页显示条数
     * @author
     * @date
     * @return com.itheima.domain.vo.PageBeanVo Vo
     */

    @GetMapping("/soulQuestionList")
    public PageBeanVo SoulQuestionList(@RequestParam(defaultValue = "1") String num,
                                       @RequestParam(defaultValue = "10") String pageSize){
        return questionManger.SoulQuestionList(Integer.valueOf(num),Integer.valueOf(pageSize));
    }




    /*
     *  问题列表
     *
     * @param num   当前页
     * @param pageSize  每页显示条数
     * @author
     * @date
     * @return com.itheima.domain.vo.PageBeanVo
     */

    @GetMapping("/questions")
    public PageBeanVo findQuestions(@RequestParam(value = "num",defaultValue = "1") String num,
                              @RequestParam(value = "pageSize",defaultValue = "10") String pageSize){
        return questionManger.findQuestions(Integer.valueOf(num),Integer.valueOf(pageSize));
    }


    /*
     *
     *
     * @param soulQuestion SoulQuestion实体类数据
     * @author
     * @date
     * @return com.itheima.domain.db.SoulQuestion
     */

    @PostMapping("/showEditQuestion")
    public SoulQuestion showEditQuestion(@RequestBody SoulQuestion soulQuestion){
        return questionManger.showEditQuestion(soulQuestion);
    }


    /*
     *  问题添加
     *
     * @param soulQuestion  SoulQuestion实体类数据
     * @author
     * @date
     * @return java.lang.String 成功返回Ok响应
     */

    @PostMapping("/saveQuestions")
    public String saveQuestions(@RequestBody SoulQuestion soulQuestion) {
       return questionManger.saveQuestions(soulQuestion);
    }




    /*
     *问题修改
     * @param soulQuestion SoulQuestion实体类数据
     * @author
     * @date
     * @return java.lang.String 成功返回Ok响应
     */

    @PostMapping("/updateQuestions")
    public String updateSoulQuestions(@RequestBody SoulQuestion soulQuestion){

        return  questionManger.updateSoulQuestions(soulQuestion);

    }

   /*
    *
    *
    * @param soulQuestion SoulQuestion实体类数据
    * @author
    * @date
    * @return java.lang.String 成功返回Ok响应
    */

    @PostMapping("/deleteQuestions")
    public String deleteQuestions(@RequestBody SoulQuestion soulQuestion){

        return  questionManger.deleteQuestions(soulQuestion);
    }
}
